<template>
  <div>
    <!-- 渲染角色列表 -->
    <el-checkbox-group v-model="roleIdList">
      <el-checkbox
        v-for="item in roleList"
        :key="item.id"
        :label="item.id"
      >{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-row
      class="footer"
      type="flex"
      justify="center"
    >
      <el-col :span="6">
        <el-button
          type="primary"
          size="small"
          @click="enterFn"
        >确定</el-button>
        <el-button
          size="small"
          @click="cancelFn"
        >取消</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'AssignRole',
  props: {
    // 用户的id 用来查询当前用户的角色信息
    userId: {
      type: String,
      default: null
    },
    //  所有角色数据
    roleList: {
      type: Array,
      default: () => []
    },
    //  员工角色数据
    roleIds: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      roleIdList: [] // 收集选中角色信息
    }
  },
  methods: {
    // 取消弹框
    cancelFn() {
      this.$emit('update:show', false)
    },
    // 确认提交
    enterFn() {
      this.$emit('update:show', false)
      this.$emit('addRoleEV', this.roleIdList)
    }
  }
}
</script>

<style lang="scss" scoped>
.footer {
  margin-top: 30px;
}
</style>
